<template>

  <el-dialog title="处理记录" :visible.sync="dialogVisible" :close-on-click-modal="false">
  	<div v-for="(item, index) in handleRecord" v-if="handleRecord.length > 0">
  		<p>{{ index + 1 }}.{{ item.handleRecord }}</p>
  		<p>{{ item.createTime }}</p>
  	</div>
  	<div v-if="handleRecord.length == 0">暂无</div>
  	<el-form ref="main-form" :gutter="24" :model="form" :rules="rules" label-width="100px" label-position="right" :inline="true" >
      <el-form-item label="处理结果" size="mini" prop="handleRecord">
        <el-input placeholder="" type="textarea" style="width: 400px;" v-model="form.handleRecord" @keyup.enter.native="submit" clearable></el-input>
      </el-form-item>  
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="close" size="small">取 消</el-button>
      <el-button type="primary" @click="submit" size="small" :loading="loading">提 交</el-button>
    </div>
  </el-dialog>

</template>

<script>

import ApiMain from '@/api/trade.complaint';
export default {
  mixins: [
  ],
  props: [
  ],
  data () {
    return {

      dialogVisible: false,
      handleRecord: [],
      form: {
      	handleRecord: ''
      },
      id: null,
      loading: false,
      rules: {
        handleRecord: [
          { required: true, message: '请输入处理结果', trigger: 'blur' },
        ],
      },
    }
  },
  methods: {
  	show(data) {
  		console.log(data)
  		if (data.handleRecord) {
  			let handleRecord = data.handleRecord.split('$$$'), arr = []
	  		handleRecord.forEach((item, index) => {
	  			let split = item.split('###')
	  			if (split.length == 2) arr.push({ handleRecord: split[0], createTime: split[1] })
	  		})
	  		this.handleRecord = arr
  		}
  		
  		this.form = {
  			id: data.id,
  			handleRecord: ''
  		}
  		this.id = data.id
  		this.dialogVisible = true
  	},

  	verifyForm () {
      var bool = true;
      this.$refs['main-form'].validate((valid) => bool = valid);
      return bool;
    },

  	close () {
      this.dialogVisible = false;
      this.$emit('dialog-close');
    },

    async submit () {

      if (! this.verifyForm()) return false;

      this.loading = true;

      try {
        await ApiMain.handleRecord(this.form);
      	this.$message({message: '添加成功', type: 'success'});
      } finally {
        this.loading = false;
        this.close();
      }
    },
  }
}

</script>